#include "Zombie.hpp"

Zombie::Zombie(std::string zname = "Zombie") :
    _Name(zname),
    height(0.0f),
    dHeight(0.0f),
    jumpsLeft(2)
{
    _Texture.loadFromFile("textures/creeper.png");
    _Sprite.setTexture(_Texture);
    _Sprite.setOrigin(_Sprite.getLocalBounds().width/2.0, _Sprite.getLocalBounds().height);
    _Sprite.setScale(0.2f, 0.2f);

    _Circle.setRadius(3.0f);
    _Circle.setOrigin(3.0f, 3.0f);
    _Circle.setOutlineThickness(1.0f);
    _Circle.setScale(1.0f,0.5f);
    _Circle.setFillColor(sf::Color(0,0,0,127));
    _Circle.setOutlineColor(sf::Color(0,0,0,63));

    _Facing = Down;
    _State = Idle;

    printf("New zombie: %s\n",_Name.c_str());
}

Zombie::~Zombie()
{
    //destr
}

Zombie::eFacing Zombie::Facing()
{
    return _Facing;
}
Zombie::eState Zombie::State()
{
    return _State;
}

void Zombie::jump(void) {
    /* Only jump if on the ground. Double jumps to come. */
    //if (height < 0.001f) {
    if (jumpsLeft > 0) {
        jumpsLeft--;
        dHeight = 3.0f;
    }
}

void Zombie::update(float d_t) {
    if ((abs(dHeight) > 0.001f) || (height > 0.001f)) {
        height += dHeight * d_t;
        dHeight -= 10.0f * d_t;
        if (height < 0.0f) {
            jumpsLeft = 2;
            height = 0.0f;
            dHeight = 0.0f;
        }
        _Circle.setRadius(3.0f - 2.5f * height);
        _Circle.setOrigin(3.0f - 2.5f * height, 3.0f - 2.5f * height);
        _Circle.setOutlineThickness(1.0f + 1.0f * height);
        _Sprite.setPosition(0.0f, -10.0f * height);
    }
}

void Zombie::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
    states.transform *= getTransform();
    target.draw(_Circle, states);
    target.draw(_Sprite, states);
}
